package gomysql

import (
	"time"

	"gorm.io/gorm"
)

//Model 基类
type Model struct {
	ID        uint  `gorm:"column:id;primary_key;AUTO_INCREMENT" json:"id"`
	CreatedAt int64 `gorm:"column:created_at" json:"created_at"`
	UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at"`
}

//BeforeCreate 钩子新增前
func (u *Model) BeforeCreate(tx *gorm.DB) (err error) {
	u.CreatedAt = time.Now().Unix()
	u.UpdatedAt = time.Now().Unix()
	return
}

// BeforeUpdate 钩子更新前
func (u *Model) BeforeUpdate(tx *gorm.DB) (err error) {
	u.UpdatedAt = time.Now().Unix()
	return
}
